<template>
	<view>
		<view class="margin flex bg-white padding">
			<!-- <view class="">
				<view class="">邀请好友+（10~15）积分</view>
				<view class="padding-top-sm text-sm text-gray">会员邀请，更有海量金币收益</view>
			</view> -->
			<view class="">
				<view class="">邀请好友</view>
				<view class="padding-top-sm text-sm text-gray">会员邀请，更有海量金币收益</view>
			</view>
			<view class=" text-center padding-top-sm padding-left-lg margin-left-lg">
				<button class="cu-btn bg-gradual-orange" @tap="yaoqing('inteuser')">邀请</button>
			</view>
		</view>
		<!-- <view class="margin flex bg-white padding">
			<view class="">
				<view class="">邀请好友+（10~15）积分</view>
				<view class="padding-top-sm text-sm text-gray">会员邀请，更有海量金币收益</view>
			</view>
			<view class=" text-center padding-top-sm padding-left margin-left">
				<button class="cu-btn bg-gradual-orange" @tap="yaoqing('inteuser2')">专属下载链接</button>
			</view>
		</view> -->

		<view class="cu-modal" :class="showModal?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">邀请好友</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					{{inteHref}}
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button data-clipboard-action="copy" :data-clipboard-text="inteHref" class="copy-btn cu-btn bg-blue margin-left"
						 @tap="copy">复制链接</button>
					</view>
				</view>
			</view>
		</view>
		
		<view class="cu-modal" :class="showModal2?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">提示</view>
					<view class="action" @tap="showModal2 = false">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					您的专属链接已复制成功，赶快去邀请好友吧
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import Clipboard from 'clipboard'
	export default {
		data() {
			return {
				showModal: false,
				showModal2: false,
				userInfo: {},
				inteHref: ''
			};
		},
		onLoad(option) {
			this.getUserInfo();
		},
		methods: {
			hideModal() {
				this.showModal = false;
			},
			getUserInfo() {
				let that = this;
				uni.getStorage({
					key: 'ONLINE_USER',
					success: function(res) {
						that.userInfo = res.data
					}
				});
			},
			yaoqing(page) {
				if (this.userInfo.invitCode == '') {
					uni.showToast({
						title: '登录信息已过期',
						icon: 'none'
					})
					return;
				}
				
				let host = window.location.protocol+"//"+window.location.host;
				let str = host + "/pages/user/"+ page +"?id=" + this.userInfo.invitCode;
				// this.inteHref = '专业的驾驶员招聘平台，每天更新各地区招聘求职信息，点击链接查看详情：' + str;
				this.inteHref = '镖掌柜，免费的驾驶员招聘平台，每天更新各地区招聘求职信息，点击链接查看详情：' + str;
				// 
				if(typeof androlua == "undefined"){
					this.showModal = true
				}else{
					let arr = [str, '致力于为全国驾驶员、车主提供招聘求职服务，每天更新大量招聘求职信息', '【镖掌柜-专招驾驶员】强烈推荐！']
					androlua.pageGoShare(arr);
					// androlua.pageGoBack();
				}
			},
			copy() {
				let _this = this;
				let clipboard = new Clipboard(".copy-btn");
				clipboard.on('success', function() {
					_this.showModal = false;
					_this.showModal2 = true;
					setTimeout(()=>{
						_this.showModal2 = false;
					}, 3000)
				});
				clipboard.on('error', function() {
					_this.showModal = false;
					setTimeout(()=>{
						uni.showToast({
							title: '复制失败'
						})
					}, 500);
				});
			}
		}
	}
</script>
